/**
 *    Copyright (C) 2008  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#include <bm_tools.h>
#include <sys/timeb.h>
#include <stdlib.h>
#include <stdio.h>

namespace cubefs {
namespace core {

long int get_random(size_t max) {
    long int val = rand() % max;
    if (val > 0) {
	return val;
    }
    else {
	return 1;
    }
}

long int get_random0(size_t max) {
    return rand() % max;
}

long int getTime() {
    struct timeb tm;
    ftime(&tm);
    return tm.time * 1000 + tm.millitm;
}

int get_number(char *st) {
    char *pEnd;
    int val = (int) strtol(st, &pEnd, 10);
    if ((*pEnd) != 0) {
	return -1;
    }
    return val;
}

int test_pow2(int value) {
    int c, cnt;
    for (c = 0, cnt = 0; c < 32; c++) {
	cnt += (value & (1 << c)) != 0;
    }

    return cnt == 1;
}

} //core
} //cubefs
